package com.ugrow.ugrowcommunity.activity.courseevaluation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ugrow.ugrowcommunity.R;
import com.ugrow.ugrowcommunity.activity.courseevaluation.CourseEvaluationActivity;
import com.ugrow.ugrowcommunity.activity.courseevaluation.bean.CourseBean;
import com.ugrow.ugrowcommunity.activity.courseevaluation.bean.Data;

import java.util.List;

public class EvaluationAdapter extends RecyclerView.Adapter<EvaluationAdapter.ViewHolder>{
    private OnItemClickListener onItemClickListener = null;
    private Context context;
    private List<Data> dataList;
    public EvaluationAdapter(Context context, List<Data> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_teacher_evealuation, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Data data = dataList.get(position);
        holder.mName.setText(data.getTchName());
        holder.mSex.setText(data.getTchSex());
        holder.mEducation.setText(data.getTchEducation());
        holder.mSystem.setText(data.getTchSystem());
        CourseBean course = data.getCourse();
        if (course ==null) {
            holder.mCourse.setText("Android开发");
        }else {
            holder.mCourse.setText(course.getcName());
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                if(onItemClickListener != null) {
                    int index = holder.getLayoutPosition();
                    onItemClickListener.onClickListener(holder.itemView,index);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView mName,mSex,mEducation,mCourse,mSystem;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mName = itemView.findViewById(R.id.evaluation_name);
            mSex = itemView.findViewById(R.id.evaluation_sex);
            mEducation = itemView.findViewById(R.id.tchEducation);
            mCourse = itemView.findViewById(R.id.tchCourse);
            mSystem = itemView.findViewById(R.id.tchSystem);
        }
    }


    //设置单击事件给外面的调用者
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    //设置接口
    public interface OnItemClickListener {
        //单击事件
        void onClickListener(View view, int position);
    }

}
